// Copyright (c) 2009 Hypirinha contributers
// This program is made available under the terms of the MIT License.
package org.hypirinha.html.output.features;

public class TypeFilter {

    @SuppressWarnings("unchecked")
    public static <T, U extends T> T filter(Object[] candidates, Class<T> targetClass, U defaultValue) {
        for (Object candidate : candidates) {
            if (targetClass.isInstance(candidate)) {
                return (T) candidate;
            }
        }
        return defaultValue;
    }
}
